import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:gourmet/components/order/index.dart';
import 'package:gourmet/route/index.dart';
import 'package:gourmet/ui/keep_alive.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/styles.dart';
import 'package:gourmet/utils/tools.dart';

class HomeOrderController extends GetxController
    with GetTickerProviderStateMixin {
  late TabController controller;
  List<String> tabs = [
    '全部',
    '待使用',
    '待评价',
    '退款',
  ];

  @override
  void onInit() {
    controller = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    controller.dispose();
    super.onClose();
  }
}

class HomeOrderView extends GetView<HomeOrderController> {
  const HomeOrderView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorsUtils.rgba(247, 247, 247, 1),
      appBar: AppBar(
        systemOverlayStyle: SystemUiOverlayStyle.dark,
        backgroundColor: Colors.white,
        automaticallyImplyLeading: false,
        centerTitle: true,
        title: Center(
          child: TextField(
            cursorHeight: 20,
            cursorWidth: 3,
            cursorRadius: const Radius.circular(2),
            cursorColor: Colors.blue,
            decoration: InputDecoration(
              fillColor: Colors.white,
              hintText: '搜索订单',
              hintStyle:
                  StylesUtils.customTextStyle(color: ColorsUtils.color9999),
              isCollapsed: true,
              filled: true,
              isDense: true,
              prefixIcon: Icon(
                Icons.search,
                color:
                    ColorsUtils.parseColorFromHexString(ColorsUtils.color9999),
                size: 20.w,
              ),
              contentPadding: const EdgeInsets.symmetric(vertical: 10),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(17.5),
                borderSide: BorderSide.none,
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(17.5),
                borderSide: BorderSide.none,
              ),
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(17.5),
                borderSide: BorderSide.none,
              ),
              constraints: const BoxConstraints.expand(width: 345, height: 35),
            ),
            readOnly: true,
            onTap: () {
              Get.toNamed(Routes.searchOrder);
            },
          ),
        ),
        bottom: PreferredSize(
          preferredSize: const Size.fromHeight(45),
          child: Container(
            alignment: Alignment.centerLeft,
            child: ToolsUtils.getClientTabBar(
                controller.tabs, controller.controller,
                isScrollable: false),
          ),
        ),
        shadowColor: ColorsUtils.rgba(245, 245, 245, 1),
        shape: Border(
            bottom: BorderSide(color: ColorsUtils.rgba(245, 245, 245, 1))),
      ),
      body: TabBarView(
        controller: controller.controller,
        children: [
          KeepAliveWrapperView(
            child: const AllOrderView(),
            callback: () {
              Get.lazyPut(() => AllOrderController());
            },
          ),
          KeepAliveWrapperView(
            child: const WaitUsedOrderView(),
            callback: () {
              Get.put(() => WaitUsedOrderController());
            },
          ),
          KeepAliveWrapperView(
            child: const WaitEvaluateOrderView(),
            callback: () {
              Get.put(() => WaitEvaluateOrderController());
            },
          ),
          KeepAliveWrapperView(
            child: const RefundOrderView(),
            callback: () {
              Get.put(() => RefundOrderController());
            },
          ),
        ],
      ),
    );
  }
}
